TWINE File Formats

Compression - EDL	Eurocom Decompression Library
The compression stamp is EDL	45 44 4C
0x0	3	EDL	compression stamp
0x3	8x	endianess	1=big endian, 0=little endian, so obviously always 1
	x3	these two bits identify compression type
		0	'store' - uncompressed (not used)
		1	LZ-derivitive
		2	RLE
0x4	4	compressed size
0x8	4	decompressed size
0xC	var	compressed data

+-+

0x54D910 is the base address added to ROM offsets used in the 800C0780 table and the data it draws.
This value is added to all ROM offsets to make a final ROM address.

Main Data Bank
  This table contains ROM offsets to each of the data banks in the game.  These are used for all image and geometry resources.
800C0780 table:	0xC1380
0x0	4	ROM offset.  add +54D910 to get true ROM address for data table
0x4	4	RDRAM start address (when loaded)
0x8	4	RDRAM end address (when loaded)
0xC	4	unknown

The format of the data:
in brief-
0x0	4	ROM offset to 'object list'.  Each entry is 0x44 in size
0x4	4	number of entries in 'object list'
0x8	4	ROM offset to unknown table.  Each entry is 0x1C in size
0xC	4	number of entries in unknown table
0x10	4	ROM offset to palette index.  Each entry is 0x8 in size
0x14	4	number of entries in palette index
0x18	4	ROM offset to image index.  Each entry is 0xC in size
0x1C	4	number of entries inimage index
0x20	4	ROM offset to palette data
0x24	4	size of palette block
0x28	4	ROM offset to images
0x2C	4	size of image block
All data blocks may optionally be EDL compressed

in detail-
'Object List'
0x0	4	ROM offset (add +54D910): table of 0x44 byte entries.
	0x0	2	Variable: object class number, room number for level data, etc.
	0x2	2	# entries in 'room position data' block, when present
	0x4	4	???
	0x8	4	ROM offset (add +54D910) for optional 'room position block'
			each entry is 0x18 in size, consisting of 6 floating-point values; sets room positions
	0xC	4	[float] x position
	0x10	4	[float] y position
	0x14	4	[float] z position
	0x18	4	[float] x rotation
	0x1C	4	[float] y rotation
	0x20	4	[float] z rotation
	0x24	4	ROM offset (add +54D910) for 'object constuction table' - see section below
	0x28	4	RDRAM pointer to image bank to use
			800C2740 table:	0xC3340
			basically, specifies an entry in the 800C0780 table that contains the images used in the object
	0x2C-0x42	2	the rest of the data appears to be a series of shorts, probably for object interlinking
0x4	4	number of entries: multiply by 0x44 for size

'Unknown Table'
0x8	4	ROM offset (add +54D910): table of 0x1C byte entries.  position and some other values
	example: C2486A7F 00000000 BEEB59DE 000C 0000 00000032 0021 0000 00000000
	0x0	4	[float] x position
	0x4	4	[float] y position
	0x8	4	[float] z position
	0xC	2	?
	0xE	2	?
	0x10	4	?
	0x14	2	?
	0x16	2	?
	0x18	4	?
0xC	4	number of entries: multiply by 0x1C for size

'Palette Index'
0x10	4	ROM offset (add +54D910): 8byte palette index
	example:	0F000000 00000010
	0x0	1	# entries -1 (assuming 16bit palettes)
	0x4	4	this is translated to an rdram address to palette
0x14	4	number of entries: multiply by 8 for size
	note: palette data follows images in rom.  Each corresponds directly to an image entry in the following segment

'Image Index'
0x18	4	ROM offset (add +54D910): table of 0xC byte image indices
	example: 0800 001F 001F 01 00 00000000
	0x0	1	format of image
			1	16bit color	256-index
			2	16bit color	16-index	mirror/clamp S
			3	16bit color	256-index	mirror/clamp S
			4	16bit color	16-index	mirror/clamp T
			5	8bit greyscale	mirror/clamp T
			6	4bit greyscale	mirror/clamp ST
			7	16bit color	256-index	mirror/clamp ST
			all 4bit images are nibble-flipped			
			8	15bit color	16-index
			9	8bit greyscale
			A	15bit color	16-index	mirror/clamp S
			B	invalid
			C	15bit color	16-index	mirror/clamp T
			D	15bit color	256-index	mirror/clamp T
			E	15bit color	16-index	mirror/clamp ST
			F	8bit greyscale	mirror/clamp ST
			10	15bit color	16-index
	0x2	2	width - 1 (same as value sent to RCP)
	0x4	2	height -1 (same as value sent to RCP)
	0x6	1	1 if indexed
	0x7	1	?
	0x8	4	offset to image, later translated to rdram address
0x1C	4	number of entries: multiply by 0xC for size

'Palette Data'
0x20	4	ROM offset (add +54D910): palettes, sometimes EDL compressed
0x24	4	size

'Image Data'
0x28	4	ROM offset (add +54D910): images, sometimes EDL compressed
0x2C	4	size: 

+_+

'object constuction table'
This consists of a table 0x20 in size setting ROM offsets to positions, RGBA values, and st (texture) positions, and triangle construction rules
0x0	4	ROM offset (add +54D910): vertex positions, given as floating-point numbers
		each entry is 0xC in size
0x4	2	number of entries: multiply by 0xC for size
0x6	2	reserved
0x8	4	ROM offset (add +54D910): RGBA values
		each entry is 0x4 in size
0xC	2	number of entries: multiply by 4 for size
0xE	2	reserved
0x10	4	ROM offset (add +54D910): st (texture) positions
		each entry is 0x4 in size
0x14	2	number of entries: multiply by 4 for size
0x16	2	reserved
0x18	4	ROM offset (add +54D910): 'triangle construction microcode'
0x1C	2	size of data segment
0x1E	2	???

'triangle construction microcode'
Similiar to FORTRAN rules.  All follow the format:
command - #entries - data
All commands are 1 byte

00	vertex list	8bit index
	1 byte	# entries
	entries:
		byte 1	position index#
		byte 2	st (texture) index#
		byte 3	RGBA index#
01	vertex list	16bit index
	1 byte	# entries
	entries:
		byte 1	position index#
		byte 3	st (texture) index#
		byte 5	RGBA index#
02	vertex list	16bit index, linear correspondance
	1 byte	# entries
	entries:
		byte 1	index# for position, texture, and RGBA values

03	vertex list	8bit index, linear correspondance 
	1 byte	# entries
	entries:
		byte 1	index# for position, texture, and RGBA values

04	generate single triangle
	entries:
		byte 1	vertex 1
		byte 2	vertex 2
		byte 3	vertex 3

05	generate triangles
	1 byte	# entries
	entries:
		byte 1	vertex 1
		byte 2	vertex 2
		byte 3	vertex 3

06	generate textured triangles	16bit image index
	2 bytes	texture index
	1 byte	# entries
	entries:
		byte 1	vertex 1
		byte 2	vertex 2
		byte 3	vertex 3

07	generate textured triangles	8bit image index
	1 byte	texture index
	1 byte	# entries
	entries:
		byte 1	vertex 1
		byte 2	vertex 2
		byte 3	vertex 3

08	generate gaussian triangles
	3 bytes	rgb colorsample
	1 byte	# entries
	entries:
		byte 1	vertex 1
		byte 2	vertex 2
		byte 3	vertex 3
09	set rgb
	1 byte	red component
	1 byte	green component
	1 byte	blue component

0A	set texture independant of palette
	1 byte	texture index

0B	set palette independant of texture
	1 byte	palette index

0C	end of code
